// pages/blessingList/blessingList.js
const app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    userInfo:{},
    list:[],
    totalPages:0,
    totalPages1:0,
    pageNumber:1,
    pageNumber1: 1,
  },
getlist(){
  var that = this
  app.req({
    url:'blessmini/user/blessList',
    data:{
      pageSize: 10,
      pageNumber: that.data.pageNumber
    },
    method: 'POST',
    success: function (res) {
      console.log('列表', res.data.rows);
      if (res.code == 200) {
        for (var i in res.data.rows) {
          res.data.rows[i].startTime = res.data.rows[i].startTime.substring(0, 10)
        }
        if(that.data.pageNumber==1){
          that.setData({
            list: res.data.rows,
            totalPages: res.data.totalPages
          })
        }else{
          that.setData({
            list: that.data.list.concat(res.data.rows),
            totalPages: res.data.totalPages
          })
        }
      }
    }
  })
},
  godetails(e){
    var id= e.currentTarget.dataset.id
    var type = e.currentTarget.dataset.type
    if(type==1){
      wx.navigateTo({
        url: '/pages/ordinaryDetails/ordinaryDetails?id=' + id,
      })
    }else{
      wx.navigateTo({
        url: '/pages/hundredDetailed/hundredDetailed?id=' + id + "&type="+type,
      })
    }
  },
  getdel(){
    var that = this
    wx.navigateTo({
      url: '/pages/blessingListDel/blessingListDel',
    })
  },
  delbtn(e){
    var that = this
    var id = e.currentTarget.dataset.id
    var type = e.currentTarget.dataset.type
    wx.showModal({
      content: '请确认是否删除',
      cancelText: "取消",
      confirmText: "确定",
      confirmColor: '#3680FE',
      cancelColor: '#333333',
      success(res) {
        if (res.confirm) {
          app.req({
            url: 'blessmini/user/userDeleteAct',
            data: {
              actId: id,
              type:type
            },
            method: 'POST',
            success: function (res) {
              console.log('返回', res);
              if (res.code == 200) {
                wx.showToast({
                  title: '删除成功',
                  duration: 2000
                })
                that.onShow()
              } else {
                wx.showToast({
                  title: res.msg,
                  icon: 'none',
                  duration: 2000
                })
              }
            }
          })
        }
      }
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var that = this
    app.getUserInfo(function (userInfo) {
      that.setData({
        userInfo: userInfo
      })
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    var that = this
    that.setData({
      pageNumber:1,
      pageNumber1:1
    })
      that.getlist()
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
    this.onShow()
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    var that = this
      if (that.data.totalPages > that.data.pageNumber) {
        that.setData({
          pageNumber: that.data.pageNumber + 1
        })
        that.getlist()
      }
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})